package com.sphd.education.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sphd.education.R;
import com.sphd.education.info.LessonInfo;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Hu on 2015/11/3.
 */
public class PushLessonsAdapter extends BaseAdapter {
    Context context;
    List<LessonInfo> lessonInfos;

    public PushLessonsAdapter(Context context, List<LessonInfo> lessonInfos) {
        this.context = context;
        this.lessonInfos = lessonInfos;
    }

    @Override
    public int getCount() {
        return lessonInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.push_lessons_item, null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.lessonName.setText(lessonInfos.get(position).getName());
        viewHolder.lessonBegintime.setText("开班时间 "+lessonInfos.get(position).getBeginTime());
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'push_lessons_item.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.lesson_name)
        TextView lessonName;
        @Bind(R.id.lesson_begintime)
        TextView lessonBegintime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
